<template>
  <el-col :span="24">
    <el-card class="page-header" shadow="never" :style="{ marginBottom: `0 !important` }">
      <el-avatar class="page-header-avatar" :src="getImgUrl(userInfo.avatar)" :alt="userInfo.username" />
      <div class="page-header-tip">
        <p class="page-header-tip-title">
          {{ handleTips() }}
        </p>

        <iframe
          frameborder="0"
          height="25"
          src="https://i.tianqi.com/?c=code&a=getcode&id=1&icon=1&site=14"
          width="100%"
        ></iframe>
      </div>
      <div class="page-header-avatar-list">
        <el-row>
          <el-col :span="12">
            <!-- <router-link to="/messageList"> -->
            <div class="grid-content bg-purple-dark" style="color: #333333">
              <el-icon><Calendar /></el-icon>
              待办项
            </div>
            <h1 style="color: #333333">{{ dbnums }}</h1>
            <!-- </router-link> -->
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple-dark" style="color: #333333">
              <el-icon><Warning /></el-icon>
              预警项
            </div>
            <h1 style="color: #333333">{{ warnnums }}</h1>
          </el-col>
        </el-row>
      </div>
    </el-card>
  </el-col>
</template>

<script>
import { useUserStore } from "@/stores/modules/user";
import { storeToRefs } from "pinia";
import { getImgUrl } from "@/api/mains";

export default defineComponent({
  components: {},
  props: {
    dbnum: {
      type: String,
      reuquired: false,
      default: ""
    },
    warnnum: {
      type: String,
      reuquired: false,
      default: ""
    }
  },
  setup(props) {
    const userStore = useUserStore();
    const { userInfo } = storeToRefs(userStore);

    const state = reactive({
      dbnums: "0",
      warnnums: "0",
      color: "#333333",
      size: "20"
    });

    const handleTips = () => {
      const hour = new Date().getHours();
      return hour < 8
        ? `早上好 ${userInfo.value.username}，又是元气满满的一天。`
        : hour <= 11
          ? `上午好 ${userInfo.value.username}，看到你我心情都变好了^_^。`
          : hour <= 13
            ? `中午好 ${userInfo.value.username}，忙碌了一上午，记得吃午饭哦。`
            : hour < 18
              ? `下午好 ${userInfo.value.username}，你一定有些累了，喝杯咖啡提提神。`
              : `晚上好 ${userInfo.value.username}，愿你天黑有灯，下雨有伞。`;
    };

    watch(
      () => [props.dbnum, props.warnnum],
      count => {
        state.dbnums = count[0];
        state.warnnums = count[1];
      }
    );

    return {
      ...toRefs(state),
      userInfo: userInfo,
      handleTips,
      getImgUrl
    };
  }
});
</script>

<style lang="scss" scoped>
.page-header {
  //transition: $base-transition;
  .page-header-avatar-list h1 {
    margin: 5px 0 0;
    font-weight: 400;
  }
  .page-header-avatar-list .el-row {
    text-align: right;
  }
  .grid-content i {
    display: inline-block;
    width: 25px;
    height: 25px;
    margin-right: 3px;
    line-height: 25px;
    text-align: center;
    border-radius: 100%;
  }
  .el-icon-document {
    color: #d46b08;
    background: #fff7e6;
    border: 1px solid #ffd592;
  }
  .el-icon-message-solid {
    color: #389e0d;
    background: #f6ffed;
    border: 1px solid #b8eb90;
  }
  :deep() {
    * {
      //transition: $base-transition;
    }
    .el-card__body {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
    }
  }
  &-avatar {
    width: 60px;
    height: 60px;
    margin-right: 20px;
    border-radius: 50%;
  }
  &-tip {
    flex: auto;
    width: calc(80% - 200px);
    min-width: 300px;
    &-title {
      margin-top: 10px;
      margin-bottom: 12px;
      font-size: 20px;
      font-weight: 400;
      color: #3c4a54;
    }
    &-description {
      //font-size: $base-font-size-default;
      color: #808695;
    }
  }
  &-avatar-list {
    flex: 1;
    min-width: 100px;
    margin-left: 20px;
    text-align: right;
    p {
      margin-right: 9px;
      line-height: 0;
    }
  }
}
</style>
